/******************************************************************************
* Copyright Authors DustinKsi@ Youibot 2019. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/

#pragma once

#include <map>

using std::pair;

namespace VEnus {
namespace Mapping {
typedef struct FeaturePairCost {
  FeaturePairCost(pair<double, double> pt1, pair<double, double> pt2) : _pt1(pt1), _pt2(pt2) {}

  template <typename T>
  bool operator()(const T* const pose, T* residual) const {
    T x_tr = T(_pt1.first) * cos(pose[2]) - T(_pt1.second) * sin(pose[2]) + pose[0];
    T y_tr = T(_pt1.first) * sin(pose[2]) + T(_pt1.second) * cos(pose[2]) + pose[1];

    residual[0] = x_tr - T(_pt2.first);
    residual[1] = y_tr - T(_pt2.second);

    return true;
  }

  const pair<double, double> _pt1, _pt2;
} FeaturePairCost;


}
}